package com.xh.chat.netty.bootstrap;

import com.xh.chat.netty.handler.WSServerInitialzer;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

public enum WSServer {

    INSTANCE;

    private final ServerBootstrap server;

    WSServer() {
        EventLoopGroup mainGroup = new NioEventLoopGroup();
        EventLoopGroup subGroup = new NioEventLoopGroup();
        server = new ServerBootstrap();
        server.group(mainGroup, subGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new WSServerInitialzer());
    }

    public void start() {
        ChannelFuture future = server.bind(8088);
        System.err.println("netty websocket server 启动完毕...");
    }
}
